package org.micro_gzm.v5;

import org.micro_gzm.v5.core.GZMRenderer;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class Main extends Activity {
	
	private GLSurfaceView view;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		view = new GLSurfaceView(this);
		
		if (detectOpenGLES20()) {
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible
            // context, and set an OpenGL ES 2.0-compatible renderer.
			view.setEGLContextClientVersion(2);
			view.setRenderer(new GZMRenderer(this));
        } 
        else {
                Log.e("MG", "OpenGL ES 2.0 not supported on device.  Exiting...");
                finish();
           
        }

		setContentView(view);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	@Override
	public void onResume() {
		super.onResume();

		//resume view
		view.onResume();
	}
	
	@Override
	public void onPause() {
		super.onPause();
		
		//pause view
		view.onPause();
	}

    private boolean detectOpenGLES20() {
    	
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        
        return (info.reqGlEsVersion >= 0x20000);
    }

}
